{% load humanize %}
{% load tagging_tags %}
{% load i18n %}
{% load deliverable_tags %}
{% load markup %}
{% load crm_organisation_tags %}

<div class="deliverable">
      {% for deliverable in deliverable_list %}
	      <h1>{{ deliverable.title }}</h1>
	      {% if deliverable.is_overdue %}
	        <p>This deliverable is <span class="warning">overdue</span></p>
	      {% endif %}
	      {% if not deliverable.is_overdue and not deliverable.completed_date %}
	        <p>This deliverable is incomplete</p>
	      {% endif %}
	      {% if deliverable.completed_date %}
	        <p>This deliverable is <span class="well-done">complete</span></p>
	      {% endif %}
	      	      
	    <p>
	      <a href="{% url deliverable_edit deliverable_id=deliverable.id %}">Edit</a>
	      <a href="{% url request_deliverable_update deliverable_id=deliverable.id %}">Request Update</a>
	    </p>

	      {{ deliverable.description|markdown }}

		<table>
          <tr><th>Owner</th><td><a href="{% url person_detail object_id=deliverable.owner.id %}">{{ deliverable.owner }}</a></td></tr>
		  <tr><th>Start Date</th><td>{{ deliverable.start_date }}</td></tr>
		  <tr><th>Due Date</th><td>{{ deliverable.target_date }}</td></tr>
		  <tr>
		    <th>Time Estimate (Minutes)</th>
		    <td>{{ deliverable.estimate }} {% if deliverable.has_bad_estimate %} <span class="warning">Scheduled tasks are estimated to take longer than the deliverable.</span>{% endif %}</td>
		  </tr>
		  <tr>
		    <th>Completed Date</th>
		    <td>
		      {% if deliverable.completed_date %}
		      Completed: {{ deliverable.completed_date }}
		      <form action="{% url deliverable_set_complete deliverable_id=deliverable.id %}" method="post">
				<input type="hidden" name="status" value="incomplete" />
				<input type="submit" value="Incomplete" />
		      </form>
		      {% endif %}
		      {% if not deliverable.completed_date %}
		      <form action="{% url deliverable_set_complete deliverable_id=deliverable.id %}" method="post">
				<input type="hidden" name="status" value="complete" />
				<input type="submit" value="Complete" />
		      </form>
		      {% endif %}
		    </td>
		  </tr>
		  <tr><th>Deliverables Type</th><td>{{ deliverable.type }}</td></tr>
		  <tr><th>Objective</th><td><a href="{% url objective_detail object_id=deliverable.objective.id%}">{{ deliverable.objective }}</a></td></tr>
		</table>
            </div>

	    <h2>Bookmarks</h2>
            <ul>
        {% for bookmark in deliverable.resource.all %}
	      <li><a href="{{ bookmark.url }}" title="{{ bookmark.note }}">{{ bookmark.description }}</a></li>  
	    {% endfor %}
            </ul>

	    <h2>Organisations</h2>
	    {% list_crm_organisations deliverable.organisation.all %}

	    <h2>Incomplete Tasks
  	        <a href="{% url deliverable_task_add deliverable_id=deliverable.id%}"><img src="{{ MEDIA_URL }}icons/add.png" alt="Add" title="Add a new task"/></a>
            </h2>
	    {% list_incomplete_tasks deliverable %}

	    <h2>Completed Tasks</h2>
	    {% list_complete_tasks deliverable %}
	  {% endfor %}